package com.wealth.scsj.b_app.model;

import com.wealth.scsj.b_app.base.MyWalletBalanceBase;
import com.wealth.scsj.b_app.bean.MyWalletBalanceBean;
import com.wealth.scsj.b_app.bean.StoreOperationMainBean;

import dkmvp.net.ResponseCallback;
import dkmvp.net.ResponseHandler;
import dkmvp.net.RetryWithDelay;
import okhttp3.RequestBody;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

/**
 * 我的钱包--- 可提现余额
 */

public class GetMyWalletBalanceModel extends BaseModel implements MyWalletBalanceBase.IModel {

    @Override
    public Subscription getMyWalletBalance(RequestBody requestBody, final ResponseCallback<MyWalletBalanceBean> callback) {
        Observable<MyWalletBalanceBean> observable = service.GetMyWalletBalance(requestBody);
        Subscription sub = observable.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .retryWhen(new RetryWithDelay(3, 3000))//总共重试3次，重试间隔3秒
                .subscribe(new Action1<MyWalletBalanceBean>() {
                    @Override
                    public void call(MyWalletBalanceBean result) {
                        callback.onSuccess(result);
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        callback.onFaild(ResponseHandler.getErrorMsg(throwable));
                    }
                });
        return  sub;
    }
}
